//#include <vector>//for some reason I had to add this here so the program compiles
//User @param1=query to be fetched from the database
//std::string SQL_query(std::string query);
//Used for queries that will have multiple needed returns. Data to be used in data[] and number of elements in array returned. 
//int SQL_query_multiple(std::string query, std::vector<std::string>& data);
#include <vector>

#ifndef QUERY_H
#define QUERY_H

/**
* \class Query
* \brief This is the sole interface with the DB for this program. All database accesses go through it
* \author Elie M. Shaccour (elie.shaccour@gmail.com)
* 
*/

class Query{

private:
/// Query string to be executed or already executed
	std::string QueryString;
/// Number of elements returned by the query
	int ReturnElementsCount;
///Vector of all the data loaded by the query
	std::vector<std::string> ReturnElements;
	
	/**     \brief Connects to the DB, username and password hardcoded 
        *       \return True if connection succesfull else false
        */
	bool ConnectToDB();

	/**     \brief Disconnects from the DB
        *       \return True if disconnection succesfull else false 
        */
	bool DisconnectFromDB();
///Last element retrieved by the query
	std::string LastElementReturned;

	/**     \brief For security option will try to protect the DB from attacks. Thus provided this function to make sure the query is safe prior to execution 
        *       \return True if query is safe
        */
	bool IsValid();//To protect the DB will create a function to test the security of the SQL query. //TODO: implement this function and call it before performing any interaction with the table
public:
	Query();

        /**     \brief Constructor that sets the query
        *       \param Query_String String with initialization of the query
        */
	Query(std::string Query_String);
	~Query();

        /**     \brief Gets the number of elements returned by the executed query 
        *       \return Int containing the count of query elements 
        */
	int GetReturnElementsCount();

        /**     \brief  Returns all the elements returned by the query
        *       \return Vector containing all the elements returned by the query 
        */
	std::vector<std::string> GetReturnElements();

        /**     \brief Some queries are expected to return a single variable, as a result,
	* instead of accessing them through the vector and having wrong index, this function
	* will get the last element retrieved. Usefull iff single variable expected
        *       \return String of the last element returned by the query
        */
	std::string GetLastElementReturned();

	/**     \brief Executes the query with the set string as a constructor or if overwritten by the set_query function 
        */
	bool Execute();

	/**     \brief Gets the element at index k as returned by the query 
        *       \param ElementPosition Needed index
        *       \return Element returned by the query at index k
        */
	std::string GetReturnElementAtPosition(int ElementPosition);

	/**     \brief Gets the elements of the query, numbered 
        *       \return String containing the query elements numbered 
        */
	std::string GetReturnElementsNumbered();

	/**     \brief Changes the query string
        *       \param String The string to set the query to
        */
	void SetQueryString(std::string String);

	/**     \brief Gets the elements of the query, unnumbered
        *       \return String containing the elements returned from the query 
        */
	std::string GetReturnElementsUnnumbered();
};

#endif
